package com.atguigu.lease.web.admin.custom.config;

import com.atguigu.lease.model.enums.ItemType;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

/**
 * @author 张智勇
 * @date 2025年08月16日 11:43
 */


@Component
public class stringToItemTypeConverter implements Converter<String, ItemType> {


    @Override
    public ItemType convert(String code) {
        for (ItemType itemType : ItemType.values()) {
            if (itemType.getCode() == Integer.parseInt(code)){
                return itemType;
            }
        }
        throw new IllegalArgumentException("非法code");
    }
}
